package com.cyd.springbootweb.sysThreadLocal;

import com.cyd.springbootweb.entity.User;

/**
 * @version 1.0.0
 * Created by cyd on 2022-10-30 12:03:10
 * @ClassName : com.cyd.springbootweb.common.SysThreadLocal
 * @Description : 类描述
 */
public class SysThreadLocal {
    private static final ThreadLocal<User> SYS_LOCAL_THREAD_USER = ThreadLocal.withInitial(User::new);

    public SysThreadLocal() {

    }

    public static void clear() {
        SYS_LOCAL_THREAD_USER.remove();
    }


    public static void setUser(User user) {
        if (null == user) {
            user = new User();
        }
        SYS_LOCAL_THREAD_USER.set(user);
    }

    public static User getUser() {
        return SYS_LOCAL_THREAD_USER.get();
    }

}
